/***************************************************************************
 *   Copyright (C) 2008 by Luca Lanziani   *
 *   luca@tulug.it   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef GESTCONNECTION_H
#define GESTCONNECTION_H
#include "util.h"

struct thread_arg{
	struct sockaddr_in thread_socket;
	int thread_socket_id;
	socklen_t thread_socket_len;
	pthread_t thread_id;
	
};

typedef struct { 
    int socket_id;
    struct thread_arg *arg;
 } sock_info;


typedef struct
  { char nick[USERNAMELEN];
    int state;
  } user_info;



typedef struct connection* connection_p;

struct connection
{
    user_info *user;
    sock_info *sock;
    pthread_mutex_t m_connection;
    connection_p next;
    connection_p prev;
};


typedef struct
  {
    connection_p head;
    connection_p tail;
    pthread_mutex_t l_mutex;
  } connections;

connections connection_list;
#endif



void init_connections_list();
connection_p new_connection (user_info *user, sock_info *sock);
user_info* new_user(char* nick, int state);
sock_info* new_sock_info(int sd,struct thread_arg *arg);
int add_connection(connection_p connection1);
int close_connection(connection_p connection);
void close_connections();
